﻿(function ($) {
    var defaults = {
        "destroy": true,
        ordering: false,
        searching: false,
        "processing": true,
        "serverSide": true,
        "info": true,
        "stateSave": true,
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
    };

    var ajaxOptions = {
        type: 'post',
        url: "",
        dataType: "json",
        data: "",
        success: function (data) {
        }
    };

    $.mainTool = {
        ajax: function (options) {
            var temp = $.extend(ajaxOptions,options );
            $.ajax(temp);
        },
        ajaxModal: function (url, title, callback) {
            $.ajax({
                type: 'get',
                url: url,
                dataType: "html",
                success: function (data) {
                    bootbox.dialog({
                        message: data,
                        title: title,
                        size: 'large',
                        buttons: {
                            submit: {
                                label: "提交",
                                className: 'btn-primary',
                                callback: function (result) {
                                    if (callback != undefined)
                                        callback(result);
                                }
                            },
                            close: {
                                label: "关闭",
                                className: 'btn-default'
                            }
                        }
                    });
                }
            });
        },
        confirm: function (message, callback) {
            bootbox.dialog({
                message: message,
                title: '',
                buttons: {
                    submit: {
                        label: "确定",
                        className: 'btn-primary',
                        callback: function (result) {
                            if (callback != undefined)
                                callback(result);
                        }
                    },
                    close: {
                        label: "取消",
                        className: 'btn-default'
                    }
                }
            });
        },
        ajaxViewModal: function (url, title) {
            $.ajax({
                type: 'get',
                url: url,
                dataType: "html",
                success: function (data) {
                    bootbox.dialog({
                        message: data,
                        title: title,
                        size: 'large',
                        buttons: {
                            close: {
                                label: "关闭",
                                className: 'btn-default'
                            }
                        }
                    });
                }
            });
        },
        Logoff: function (item) {
            $(item).children("form").submit();
        }
    };

    $.fn.mainToolDataTable = function (options) {
        var temp = $.extend(options, defaults);
        this.DataTable(temp);

        this.wrap('<div class="table-responsive" />');
        this.parent("div.table-responsive").slimScrollHorizontal({
            color: '#fff',
            size: '3px',
            railOpacity: '1',
            width: '100%',
            positon: 'bottom',
            start: 'left',
            railVisible: true,
            distance: "3px",
        });
    };
})(jQuery);
